Page({
  goLogin() {
    wx.navigateTo({
      url: '/pages/login/index',
    })
  },
  onShow() {
    if (!getApp().token) return
    if (getApp().userProfile.nickName) {
      this.setData({ ...getApp().userProfile })
    } else {
      //登录才去获取用户资料
      this.getUserProfile()
    }

  },
  //获取用户资料
  async getUserProfile() {
    const res = await wx.http.get('/userInfo')
    console.log(res);
    this.setData({ ...res })
    getApp().userProfile = {
      nickName: res.nickName,
      avatar: res.avatar
    }
  }
})
